/*
  AspNetSwitch for EverEdit
  -------------------
    Written by vinsa (vinsapro@gmail.com)
*/

(function(){
	function fileExists(filename) {
	    var fso = new ActiveXObject("Scripting.FileSystemObject");
	    return fso.FileExists(filename);
	}

	function openFile(filename){
		if (fileExists(filename)){
			App.OpenDoc(filename);
			return true;
		}
		return false;
	}

	function getExt(){
		var fullPath = ActiveDoc.PathName;
		var pos = fullPath.lastIndexOf(".");
		return fullPath.substring(pos + 1, fullPath.length);
	}

	function getAspx(){
		var fullPath = ActiveDoc.PathName;
		var pos = fullPath.lastIndexOf(".");
		return fullPath.substring(0, pos);
	}

	var ext = getExt().toLowerCase();
	if (ext == "cs" || ext == "vb"){
		openFile(getAspx());
	} else if (ext == "aspx" || ext == "ascx" || ext == "ashx" || ext == "asax") {
		openFile(ActiveDoc.PathName + ".cs") || openFile(ActiveDoc.PathName + ".vb") ;
	}
})()